import request from '@/config/axios'
import { MediaBasicInfosReqVO } from '@/types/smart-media'

const baseURL = '/system/media-manager'

export const getMediaInfo = (data: {
  mediaId?: string
  inputUrl?: string
  outputType?: 'oss' | 'cdn'
}) => {
  // 参数校验
  if (!data.mediaId && !data.inputUrl) throw new Error('请输入 mediaId 和 inputUrl 其中一个')
  // 默认值
  data = Object.assign({ outputType: 'oss' }, data)

  return request.post({
    url: `${baseURL}/media-info`,
    data
  })
}

export const listPublicMediaBasicInfos = (data: {
  mediaTagId: string
  pageNo?: number
  pageSize?: number
}) => {
  // 默认值
  data = Object.assign({ pageNo: 1, pageSize: 10 }, data)

  return request.post({
    url: `${baseURL}/list-public-media-basic-infos`,
    data
  })
}

export const listMediaBasicInfos = (data: MediaBasicInfosReqVO) => {
  // 默认值
  data = Object.assign({ pageNo: 1, pageSize: 10 }, data)
  data.includeFileBasicInfo = true

  return request.post({
    url: `${baseURL}/list-media-basic-infos`,
    data
  })
}

export const listAllPublicMediaTags = (data: { entityId?: string; businessType?: string }) => {
  // 默认值
  data = Object.assign({ businessType: 'sticker' }, data)

  return request.post({
    url: `${baseURL}/list-all-public-media-tags`,
    data
  })
}

export const batchGetMediaInfos = (data: { additionType: string; mediaIds: string }) => {
  if (!data.mediaIds) throw new Error('请输入 mediaIds')

  return request.post({
    url: `${baseURL}/batch-get-media-infos`,
    data
  })
}
